<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>公告通知管理</title>
    <#include "/common/link.ftl">
</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="notice"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>公告通知管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <div style="margin: 20px 0px 0px 10px">
                    <form class="form-inline" id="searchForm" action="/notice/list" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">

                           <div class="form-group">
                                <label>创建日期查询：</label>
                                <input placeholder="请输入开始日期" name="createTime" value="${(qo.createTime?string("yyyy-MM-dd HH:mm"))!}" type="text" class="form-control input-dateTime"/> -
                                <input placeholder="请输入结束日期" name="endTime" value="${(qo.endTime?string("yyyy-MM-dd HH:mm"))!}" type="text" class="form-control input-dateTime"/>
                            </div>

                        <div class="form-group">
                            <label>公告级别：</label>
                            <select class="form-control" name="lev" >
                                <option value="">请选择级别</option>
                                <#list stas as s>
                                    <option value="${s.getValue()}">${s.getName()}</option>
                                </#list>
                            </select>
                            <script>
                                $('[name=lev]').val(${qo.lev});
                            </script>
                        </div>
                        <div class="form-group">
                            <label>阅读状态：</label>
                            <select class="form-control" name="alreadyRead">
                                <option value="">全部</option>
                                <option value="0">未读</option>
                                <option value="1">已读</option>
                            </select>
                        </div>
                        <script>
                            $('[name=alreadyRead]').val(${qo.alreadyRead});
                        </script>

                            <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询</button>

                            <a href="#" class="btn btn-success btn-input">
                                <span class="glyphicon glyphicon-plus"></span> 添加
                            </a>
                    </form>

                </div>
                <div class="box-body table-responsive">
                <table class="table table-hover table-bordered table-striped">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>公告标题</th>
                        <th>创建人</th>
                        <th>创建时间</th>
                        <th>公告级别</th>
                        <th>是否已读</th>
                        <th>发布状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <#list pageInfo.list as n>
                        <tr>
                            <td>${n.id}</td>
                            <td>${n.title}</td>
                            <td>${n.name}</td>
                            <td>${(n.creatTime?string("yyyy-MM-dd HH:mm"))!}</td>
                            <td>${n.levalName}</td>
                            <td><span style="color:red">${n.read?string("已读","未读")}</span></td>
                            <td>${n.status?string("已发布","未发布")}</td>
                            <td>
                                <a class="btn btn-success btn-xs  btn-show" data-id="${n.id}" >
                                    <span class="glyphicon glyphicon-phone-alt"></span> 查看</a>
<#--                              <#if n.status==false>-->
                                <a class="btn btn-primary btn-xs btn-input" data-json='${n}' data-id="${n.id}">
                                    <span class="glyphicon glyphicon-pencil"></span> 编辑
                                </a>
<#--                              </#if>-->
                                <a class="btn btn-xs btn-info btn-push" data-id="${n.id}">
                                    <span class="glyphicon glyphicon-share"></span> 发布</a>
                                <a class="btn btn-xs btn-danger btn-remove" data-id="${n.id}">
                                    <span class="glyphicon glyphicon-remove"></span> 取消</a>
                            </td>
                        </tr>
                    </#list>


                    </tbody>
                </table>
                <#include "/common/page.ftl">
                </div>
            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>

<!--模态框-->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
            </div>

            <form id="editForm" action="/notice/saveOrUpdate" method="post" >
                <div class="modal-body">
                    <input type="hidden" name="id">
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">公告标题：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="title" placeholder="请输入公告标题"/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">公告内容：</label>
                        <div class="col-sm-7">
                            <textarea type="text" class="form-control" rows="8" name="vals"
                                      placeholder="请输入公告内容"></textarea>
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">公告级别：</label>
                        <div class="col-sm-7">
                            <select class="form-control" name="leval" >
                                <option value="">请选择级别</option>
                                <#list stas as s>
                                    <option value="${s.getValue()}">${s.getName()}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary btn-submit">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
<#--    编辑和新增-->
    $(".btn-input").click(function () {
        var notic = $(this).data('json');
        //清空
        $('#editForm input').val("");
        $('#editForm select').val("");
        $('#editForm textarea').val("");

        $.post("/notice/power",function (data) {
            if (data.success){
                $("#editModal").modal('show');
                if (notic){
                    $('[name=id]').val(notic.id);
                    $('[name=title]').val(notic.title);
                    $('[name=vals]').val(notic.vals);
                    $('[name=leval]').val(notic.leval);
                }
            }else{
                Swal.fire({
                    text: data.msg,
                    icon: 'warning',
                });
            }
        });
    });

    //发布
    $('.btn-push').click(function () {
        var id = $(this).data('id');
        $.post("/notice/power",function (data) {
            if (data.success){
                   $.post("/notice/statu?id="+id,function (data) {
                         if (data.success){
                                window.location.href="/notice/updatepack?id="+id;
                         }else{
                             Swal.fire({
                                 text: data.msg,
                                 icon: 'warning',
                             });
                         }

                   });


            }else{
                Swal.fire({
                    text: data.msg,
                    icon: 'warning',
                });
            }
        });
    });

    //跳转show页面
    $('.btn-show').click(function () {
        var id = $(this).data('id');
      window.location.href="/notice/show?id="+id;
    });


//    取消
    $('.btn-remove').click(function () {
        var id = $(this).data("id");
        $.post("/notice/power",function (data) {
            if (data.success){
                Swal.fire({
                    title: '确定取消吗?',
                    text: "取消将永久删除数据!",
                    icon: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                }).then((result) => {
                    if (result.value) {
                        //点击确认按钮后做的事情
                        window.location.href="/notice/delete?id="+id;
                    }
                });

            }else{
                Swal.fire({
                    text: data.msg,
                    icon: 'warning',
                });
            }
        });
    })

</script>

</body>
</html>
